package com.fsbm.ctech.maxis.ebpsbackend;

import java.net.URLEncoder;
import java.util.Date;

import org.apache.commons.codec.binary.Base64;

import com.myebills.ebpsfrontend.utils.DateUtil;

public class UrlGenerator {

	public static String getBillUrl(ConfigObject cfgObj, String acctno, String msisdn, String channelid) throws Exception{
		String url = cfgObj.billUrl;
		String param="";
		if(acctno != null) {
			param += acctno;
		}
		if (msisdn != null) {
			param += "|" + msisdn;
		}
		if (channelid != null) {
			param += "|" + channelid;
		}
		param += "|" + DateUtil.formatDate(new Date(), cfgObj.billUrlTimeFormat == null ? "yyMMdd" : cfgObj.billUrlTimeFormat);
		
		//Encrypt
		byte[] base64Encoded = Base64.encodeBase64(
				CryptoUtil.AESEnccrypt(cfgObj.privateKeyFile, cfgObj.privateKeyPass, cfgObj.secretKeyFile, param));
		
		url += URLEncoder.encode(new String(base64Encoded),"UTF-8");
		return url;
	}
	
	
}
